function [x_winsor] = winsorize(x,q)
   % winsorize variable x, symmetric using quantile q and 1-q
   
   qh = quantile(x,1-q);
   ql = quantile(x,q);
   
   x_winsor = x;
   x_winsor(x<ql) = ql;
   x_winsor(x>qh) = qh;
end

